<html>
<head>
 <title>Anti-arithmetic permutations</title>
</head>

<body>
<center>
<h1>POI III Stage III Problem 4</h1>
<h1>Anti-arithmetic permutations</h1>
</center>
<p>We call a permutation <i>p<sub>0</sub></i>, <i>p<sub>1</sub></i>, ... , <i>p<sub>n-1</sub></i>
 of integers 0, 1, ...
, <i>n</i>-1 anti-arithmetic, when there are no three-term
arithmetic series in this permutation, i.e. there are no such three indices
<i> i</i> &lt; <i> j</i> &lt; <i>k</i>, that integers <i> p<sub>i</sub></i>, <i> p</i><sub><i>j</i></sub>,
<i> p</i><sub><i>k</i></sub> make an arithmetic series. For example the series of integers 3, 1,
0, 4, 2 is an anti-arithmetic permutation of integers 0, 1, 2, 3, 4. The series
0, 5, 4, 3, 1, 2 is not an anti-arithmetic permutation, because its first, fifth
and sixth term: 0, 1, 2 form an arithmetic series (as well as its second, forth
and fifth term: 5, 3, 1 and second third and forth term: 5, 4, 3 form arithmetic series).
<h2>Task</h2>
<p>Write a program that:</p>
<ul>
  <li>reads one positive integer <i>n</i> from the text file PER.IN,</li>
  <li>computes any anti-arithmetic permutation of numbers 0, 1, ... , <i>n</i>-1 and writes it into the text file
    PER.OUT.</li>
</ul>
<h2>Input</h2>
 
<p>
There is one positive integer <i>n</i>, 3 &lt;= <i> n</i> &lt;= 1000000, written in the text
file PER.IN.&nbsp;</p>
 
<h2>Output</h2>
 
<p>
The output file PER.OUT should be composed of <i> n</i> lines. These lines should
contain different integers from the set {0, 1, ... , <i>n</i>-1}, one in each line. The
numbers in the consecutive lines should form an anti-arithmetic permutation of
numbers 0, 1, ..., <i>n</i>-1.</p>
 
<h2>Example</h2>
 
<p>
If there is number 5 written in the input file PER.IN, then one of the correct
solutions is the following file PER.OUT :<br>
3<br> 
1<br>
0<br>
4<br>
2<br>
</p>
 </body>

</html>
